var a = require("../export.js");

getApp();

Page({
    data: {
        carLevellist: [],
        car_name: "",
        coupon: "",
        img_url: "",
        max_price: "",
        min_price: "",
        num: "",
        options: {}
    },
    onLoad: function(e) {
        var n = this;
        n.setData({
            options: e
        }), console.log(e), 1 == e.flag ? a.requestUtil.post(a._DuoguanData.duoguan_host_api_url + "/index.php/addon/DuoguanCar/Api/getCListInfo.html", e, function(a) {
            n.setData({
                car_name: a.car_name,
                coupon: a.coupon,
                img_url: a.img_url,
                max_price: a.max_price,
                min_price: a.min_price,
                num: a.num
            });
        }) : a.dg.getStorage({
            key: "CarInfo",
            success: function(a) {
                console.log(a.data), a.data.chexing.length > 1 ? a.data.chexing.map(function(a) {
                    e.id == a.id && n.setData({
                        car_name: a.car_name,
                        coupon: a.coupon,
                        img_url: a.img_url,
                        max_price: a.max_price,
                        min_price: a.min_price,
                        num: a.num
                    });
                }) : n.setData({
                    car_name: a.data.chexing[0].car_name,
                    coupon: a.data.chexing[0].coupon,
                    img_url: a.data.chexing[0].img_url,
                    max_price: a.data.chexing[0].max_price,
                    min_price: a.data.chexing[0].min_price,
                    num: a.data.chexing[0].num
                });
            },
            fail: function() {
                a.dg.alert("未获取到此汽车信息");
            }
        }), this.getCarLevel(e);
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {
        var e = this.data.options;
        this.getCarLevel(e), a.dg.stopPullDownRefresh();
    },
    onReachBottom: function() {},
    getCarLevel: function(e) {
        var n = this;
        a.requestUtil.post(a._DuoguanData.duoguan_host_api_url + "/index.php/addon/DuoguanCar/Api/getCarLevel.html", e, function(a) {
            n.setData({
                options: e,
                carLevellist: a
            });
        });
    },
    toCarInfo: function(a) {
        var e = a.currentTarget.dataset.id;
        wx.navigateTo({
            url: "/pages/car/detail/detail?id=" + e
        });
    },
    goXunJia: function(a) {
        var e = a.currentTarget.dataset.car_goods_id, n = a.currentTarget.dataset.car_goods_level_id;
        console.log(n), wx.navigateTo({
            url: "/pages/car/bespeak/bespeak?car_goods_id=" + e + "&car_goods_level_id=" + n
        });
    },
    goShiJia: function(a) {
        var e = a.currentTarget.dataset.car_goods_id, n = a.currentTarget.dataset.car_goods_level_id;
        wx.navigateTo({
            url: "/pages/car/bespeak-shijia/bespeak-shijia?car_goods_id=" + e + "&car_goods_level_id=" + n
        });
    }
});